#ifndef EVENT_H_
#define EVENT_H_

/*
	Copyright (C) 2011 Salil Bhagurkar

	This file is part of illusion

	illusion is free software: you can redistribute it and/or modify
	it under the terms of the GNU Lesser General Public License as
	published by the Free Software Foundation, either version 3 of
	the License, or (at your option) any later version.

	illusion is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU Lesser General Public License for more details.

	You should have received a copy of the GNU Lesser General Public
	License along with illusion. 
	If not, see <http://www.gnu.org/licenses/>.
*/

#include <kernel/process.h>

#define EVENT_NAME_LEN 32

/*
 * Default raise reason is EVENT_REASON_EVENT
 * EVENT_REASON_DEINIT is when the event is deinitialized from the system
 */
enum {EVENT_REASON_EVENT = 0, EVENT_REASON_DEINIT};

struct event {
	char name[EVENT_NAME_LEN];			//Name of the event
	uint_t raise_reason;				//The reason why this event was raised.
	void *raise_data;				//Data stored when an event is raised. This is only used for the people who get woken up for this raise.
	struct process_waitlist *waits, *waits_tail;	//List of processes waiting for this event
	struct event *next, *prev;
};

void event_register(struct event *e);
void event_unregister(struct event *e);
struct event *event_create(char *name);
void event_free(struct event *e);
void event_raise(struct event *event, void *data);
void event_wait(void **data, struct event *event);
struct event *event_get(char *name);

#endif /* EVENT_H_ */
